package com.zat.mes.andrmes.dofun.system.adapter

import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zat.mes.andrmes.R
import com.zat.mes.andrmes.data.ClockBean
import com.zat.mes.andrmes.utils.DateUtil

/**
 * @author zy
 * @date :2020-02-16 00:06
 * @description: 签到adapter
 */
class ClockAdapter(layoutResId: Int, itemChildClickListener: ItemChildClickListener) :
    BaseQuickAdapter<ClockBean, BaseViewHolder>(layoutResId) {
    var clickListener = itemChildClickListener

    override fun convert(helper: BaseViewHolder, item: ClockBean) {
        helper.setText(
            R.id.tvTimeItemClock,
            DateUtil.formatDate(DateUtil.strToDateLong(item?.loginTime), "HH:mm")
        )
        if ("1".equals(item?.type)) {
            helper.setText(R.id.tvTypeNameItemClock, context.getString(R.string.text_work_sign))
            helper.setText(R.id.tvTypeItemClock, context.getString(R.string.text_up))
            helper.getView<TextView>(R.id.tvTypeItemClock)
                .setBackgroundColor(ContextCompat.getColor(context, R.color.color_theme))
        } else {
            helper.setText(R.id.tvTypeNameItemClock, context.getString(R.string.text_off_sign))
            helper.setText(R.id.tvTypeItemClock, context.getString(R.string.text_down))
            helper.getView<TextView>(R.id.tvTypeItemClock)
                .setBackgroundColor(ContextCompat.getColor(context, R.color.color_yellow))

        }

        if ("0".equals(item?.status)) {
            //未审核
            helper.getView<LinearLayout>(R.id.llItemClock)
                .setBackgroundColor(ContextCompat.getColor(context, R.color.color_EEF3F8))
            helper.getView<View>(R.id.lineItemClock).visibility = View.VISIBLE
            helper.getView<ImageView>(R.id.ivDeleteItemClock).visibility = View.VISIBLE
            helper.getView<TextView>(R.id.tvStatusItemClock).visibility = View.GONE
        } else {
            //已审核
            helper.getView<LinearLayout>(R.id.llItemClock)
                .setBackgroundColor(ContextCompat.getColor(context, R.color.color_E6EBF1))
            helper.getView<View>(R.id.lineItemClock).visibility = View.GONE
            helper.getView<ImageView>(R.id.ivDeleteItemClock).visibility = View.GONE
            helper.getView<TextView>(R.id.tvStatusItemClock).visibility = View.VISIBLE
        }
        helper.getView<ImageView>(R.id.ivDeleteItemClock).setOnClickListener {
            item?.let { it1 -> clickListener?.onClick(it1) }
        }

    }


    interface ItemChildClickListener {
        fun onClick(bean: ClockBean)
    }
}